package com.zj.reflect;

import java.lang.reflect.Field;

public class ReflectUtil {
    public static Class<?> getClassByType(String params) throws Exception {
        if(params!=null){
            return Class.forName(params);
        }
        return null;
    }

    public static Object getFieldValue(Class clazz,String fieldName,Object param) throws Exception {
        Field declaredField = clazz.getDeclaredField(fieldName);
        declaredField.setAccessible(true);
        return declaredField.get(param);
    }

    public static void setFieldValue(Object obj,String fieldName,Object value) throws Exception {
        Field declaredField = obj.getClass().getDeclaredField(fieldName);
        declaredField.setAccessible(true);
        declaredField.set(obj,value);
    }
}
